<?php

use App\Middleware\FavIconMiddleware;
use Swoft\Db\Database;
use Swoft\Http\Server\HttpServer;
use Swoft\Http\Server\Middleware\ValidatorMiddleware;
use Swoft\Redis\RedisDb;
use Swoft\Rpc\Server\ServiceServer;
use Swoft\Server\SwooleEvent;
use Swoft\Task\Swoole\FinishListener;
use Swoft\Task\Swoole\TaskListener;

return [
    'logger'     => [
        'flushRequest' => false,
        'enable'       => false,
        'json'         => false,
    ],
    'httpServer' => [
        'class'   => HttpServer::class,
        'port'    => env('HTTP_PORT', 18306),
        'listener' => [
            'rpc' => bean('rpcServer')
        ],
        'on'       => [
//            SwooleEvent::TASK   => bean(SyncTaskListener::class),  // Enable sync task
            SwooleEvent::TASK   => bean(TaskListener::class),  // Enable task must task and finish event
            SwooleEvent::FINISH => bean(FinishListener::class)
        ],
        /* @see HttpServer::$setting */
        'setting' => [
            'worker_num'            => 6,
            'task_worker_num'       => 12,
            'task_enable_coroutine' => true,
        ]
    ],
    'httpDispatcher'    => [
        // Add global http middleware
        'middlewares'      => [
            FavIconMiddleware::class
        ],
        'afterMiddlewares' => [
            ValidatorMiddleware::class,
        ]
    ],
    'rpcServer'         => [
        'class' => ServiceServer::class,
        'port'    => env('RPC_PORT', 18307),
    ],
    'db'  => [
        'class'  => Database::class,
        'charset'  => 'utf8mb4',
        'prefix'   => 'bcs_',
        'options'  => [],
        'config'   => [
            'collation' => 'utf8mb4_general_ci',
            'strict'    => false,
            'timezone'  => '+8:00',
            'modes'     => 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES',
        ],
        'writes' => [
            [
                'dsn'      => env('DB_MASTER1_DSN', ''),
                'username' => env('DB_MASTER1_USERNAME'),
                'password' => env('DB_MASTER1_PASSWORD'),
            ],
        ],
        'reads'  => [
            [
                'dsn'      => env('DB_NODE1_DSN', ''),
                'username' => env('DB_NODE1_USERNAME'),
                'password' => env('DB_NODE1_PASSWORD'),
            ],
        ],
    ],
    'db.pool'         => [
        'class'    => \Swoft\Db\Pool::class,
        'database' => bean('db'),
        'minActive'   => 10,
        'maxActive'   => 20,
        'maxWait'     => 0,
        'maxWaitTime' => 0,
        'maxIdleTime' => 60,

    ],
    'redis'             => [
        'class'    => RedisDb::class,
        'host'     => env('REDIS_HOST', '127.0.0.1'),
        'port'     => env('REDIS_PORT', 6379),
        'database' => 0,
        'password' => env('REDIS_PASSWORD',''),
        'retryInterval' => 10,
        'readTimeout'   => 0,
        'timeout'       => 2,
        'option'   => [
            'prefix' => 'swoft:',
        ]
    ],
    'redis.pool'     => [
        'class'   => \Swoft\Redis\Pool::class,
        'redisDb' => \bean('redis'),
        'minActive'   => 10,
        'maxActive'   => 20,
        'maxWait'     => 0,
        'maxWaitTime' => 0,
        'maxIdleTime' => 60,
    ],

    // 配置中心
    'apollo' => [
        'host'    => env('APOLLO_HOST', '127.0.0.1'),
        'port'    => env('APOLLO_PORT', 9999),
        'appId'    => env('APOLLO_APP_ID', ''),
        'clusterName'    => 'default',
        'timeout' => 120
    ],
    'consul' => [
        'host' => env('CONSUL_HOST', '127.0.0.1'),
        'port' =>env('CONSUL_PORT', '8500'),
    ],
    'migrationManager' => [
        'migrationPath' => '@app/Migration',
    ],

    // 国际话
    'i18n'  => [
        // 设置到文本资源目录
        'resoucePath' => '@resource/language/', // 结尾斜线必须

        // 设置默认文本文件夹名称
        // 未填写则默认 en 文件夹
        'defaultLanguage'   => 'zh',

        // 设置默认文本文件名称
        // 未填写则默认 default.php
        'defualtCategory'   => 'default',
    ],
];
